/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SubsistemaPaciente;

import clienteSandraParada.Login;
import clienteSandraParada.Mensajeria;
import com.toedter.calendar.JDateChooser;
import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import ordenar.Ordenar;

/**
 *
 * @author hernan
 */
public class DialogoInfoPaciente extends javax.swing.JDialog {

    /**
     * Creates new form DialogoInfoPaciente
     */
    private Paciente p;

    public DialogoInfoPaciente(java.awt.Frame parent, boolean modal, Paciente p) throws FileNotFoundException, IOException {
        super(parent, modal);
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/GUI/Img/logo2.png")).getImage());
        this.p = p;
        this.direccion.cargar();
        cargarDatosComboDerivacion();
        this.cargarDatosCombos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        rut = new componentes.Rut();
        jLabel5 = new javax.swing.JLabel();
        campoNombres = new javax.swing.JTextField();
        campoApellidoPat = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        campoApellidoMat = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        dateChooserFechaNac = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        campoProfesion = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        comboBoxPrevision = new javax.swing.JComboBox();
        comboBoxEstadoCivil = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        campoEdad = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        comboBoxSexo = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        direccion = new componentes.Direccion();
        jPanel4 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        telefono = new componentes.Telefono();
        celular = new componentes.Celular();
        botonAceptar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        mensajeriaInformacion = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        email = new componentes.Correo();
        jLabel21 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        comboDerivado = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos personales"));

        jLabel9.setText("Rut:");

        jLabel5.setText("*");

        jLabel10.setText("Nombres:");

        jLabel11.setText("Apellido paterno:");

        jLabel15.setText("*");

        jLabel12.setText("Apellido materno:");

        jLabel16.setText("*");

        jLabel18.setText("*");

        dateChooserFechaNac.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateChooserFechaNacPropertyChange(evt);
            }
        });

        jLabel2.setText("Fecha nacimiento:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(campoNombres, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                                .addComponent(campoApellidoPat, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addComponent(campoApellidoMat, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dateChooserFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel15)
                                .addComponent(jLabel16))
                            .addComponent(jLabel18))
                        .addGap(0, 11, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rut, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(68, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(rut, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(campoApellidoPat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11))
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(campoApellidoMat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(dateChooserFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(" "));

        jLabel4.setText("Profesión:");

        jLabel3.setText("Previsión:");

        comboBoxPrevision.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar" }));

        comboBoxEstadoCivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar" }));

        jLabel1.setText("Estado civil:");

        campoEdad.setEnabled(false);

        jLabel7.setText("Edad:");

        jLabel8.setText("*");

        comboBoxSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar", "Masculino", "Femenino" }));

        jLabel24.setText("Sexo:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(comboBoxPrevision, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(comboBoxEstadoCivil, javax.swing.GroupLayout.Alignment.LEADING, 0, 179, Short.MAX_VALUE)
                            .addComponent(comboBoxSexo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(campoProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23))))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel24, jLabel3, jLabel4, jLabel7});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxEstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxPrevision, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Contacto **"));

        jLabel14.setText("Teléfono:");

        jLabel20.setText("Celular:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(telefono, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(celular, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                .addContainerGap(78, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addGap(17, 17, 17)
                        .addComponent(jLabel20)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botonAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Aceptar.png"))); // NOI18N
        botonAceptar.setText("Aceptar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        mensajeriaInformacion.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        mensajeriaInformacion.setText("Área de mensajería");

        jLabel22.setText("*   Campos obligatorios");

        jLabel25.setText("** Al menos ingresar un campo");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(" "));

        jLabel21.setText("E-mail:");

        jLabel13.setText("Derivado:");

        comboDerivado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar:" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                    .addComponent(jLabel21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(email, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(comboDerivado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel21)
                    .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(comboDerivado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel25, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(botonCancelar)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4))
                    .addComponent(direccion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(mensajeriaInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(direccion, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel25))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botonAceptar)
                        .addComponent(botonCancelar)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mensajeriaInformacion)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void agregarFocusListenerRutPaciente() {
        this.normalizarMensajeria();
        rut.getRut().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                if (!rut.isValido()) {
                    cambiarEtiquetaMensajeria("Debe ingresar un rut válido", Color.red);
                    rut.getRut().requestFocus();
                } else {
                    normalizarMensajeria();
                    service.Paciente p = (service.Paciente) cargarPaciente(rut.getRut().getText());
                    if (p != null) {
                        cambiarEtiquetaMensajeria("El rut ingresado ya se encuentra en el sistema", Color.red);
                        rut.getRut().requestFocus();
                    }
                }
            }
        });
    }

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        this.normalizarMensajeria();
        if (camposObligatoriosLlenos() && alMenosUnCampo()) {
            this.dispose();
            service.Paciente sp = (service.Paciente) cargarPaciente(rut.getRut().getText());
            String comuna = validarCombo(direccion.getComuna());
            String provincia = validarCombo(direccion.getProvincia());
            String region = validarCombo(direccion.getRegion());
            String estadoCivil = validarCombo(comboBoxEstadoCivil);
            String prevision = validarCombo(comboBoxPrevision);
            String sexo = validarCombo(comboBoxSexo);
            String derivado = validarCombo(comboDerivado);
            String fecha = validarFecha();


            if (botonAceptar.getText().equalsIgnoreCase("Guardar")) {
                String anterior = llenarString(sp);
                modificarPac(sp, comuna, estadoCivil, prevision, provincia, region, sexo, fecha, derivado);
                String nuevo = llenarString(sp);
                registrar(Login.getUser(), "Paciente", "Modificó paciente: " + sp.getRut(), anterior, nuevo);
                if (!derivado.equals("")) {
                    if (!isPacienteEnlazadoAProfesionalExterno(sp.getRut(), this.buscarRutProfesionalExterno(derivado))) {
                        agregarEnlaceProfesionalExternoPaciente(this.buscarRutProfesionalExterno(derivado), sp.getRut());
                    }
                }
                p.actualizarTabla();
            } else if (botonAceptar.getText().equalsIgnoreCase("Agregar")) {
                if (rut.isValido()) {
                    agregarPaciente(campoApellidoPat.getText(), campoApellidoMat.getText(), direccion.getBloque().getText(), direccion.getCalle().getText(), celular.getCelular().getText(), comuna, direccion.getDepartamento().getText(), email.getCorreo().getText(), estadoCivil, fecha, campoNombres.getText(), direccion.getNumero().getText(), prevision, campoProfesion.getText(), provincia, region, rut.getRut().getText(), direccion.getSector().getText(), telefono.getTelefono().getText(), sexo, derivado, true);
                    service.Paciente sp2 = (service.Paciente) cargarPaciente(rut.getRut().getText());
                    String nuevo = llenarString(sp2);
                    registrar(Login.getUser(), "Paciente", "Agregó paciente: " + sp2.getRut(), "No aplica", nuevo);
                    if (p != null) {
                        p.actualizarTabla();
                    }
                    if (!derivado.equals("")) {
                        if (!isPacienteEnlazadoAProfesionalExterno(rut.getRut().getText(), this.buscarRutProfesionalExterno(derivado))) {
                            agregarEnlaceProfesionalExternoPaciente(this.buscarRutProfesionalExterno(derivado), rut.getRut().getText());
                        }
                    }
                } else {
                    this.cambiarEtiquetaMensajeria(Mensajeria.mensajeRutValido(), Color.red);
                }
            }
        } else if (!camposObligatoriosLlenos()) {
            this.cambiarEtiquetaMensajeria(Mensajeria.mensajeCamposObligatorios(), Color.red);
        } else if (!alMenosUnCampo()) {
            this.cambiarEtiquetaMensajeria("Debe ingresar un teléfono o celular", Color.red);
        }
    }//GEN-LAST:event_botonAceptarActionPerformed

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_botonCancelarActionPerformed

    public String buscarRutProfesionalExterno(String nombreProfesional) {
        java.util.List<service.ProfesionalExterno> profesionales = listarProfesionalesExternos();
        for (service.ProfesionalExterno pro : profesionales) {
            String profesional = pro.getNombres() + " " + pro.getApellidoPaterno() + " " + pro.getApellidoMaterno();
            if (profesional.equals(nombreProfesional)) {
                return pro.getRut();

            }
        }
        return null;
    }
    
    private void dateChooserFechaNacPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateChooserFechaNacPropertyChange

        String edad = Integer.toString(calcularEdad(capturarFecha()));
        if (!edad.equals("-1")) {
            this.campoEdad.setText(edad + " años");
        } else {
            this.campoEdad.setText("");
        }
    }//GEN-LAST:event_dateChooserFechaNacPropertyChange

    public void cambiarEtiquetaMensajeria(String mensaje, Color color) {
        mensajeriaInformacion.setText(mensaje);
        mensajeriaInformacion.setForeground(color);
    }

    public boolean camposObligatoriosLlenos() {
        boolean b = false;
        if (!rut.getRut().getText().equals("")
                && !campoNombres.getText().equals("")
                && comboValido(comboBoxPrevision)
                && !campoApellidoPat.getText().equals("")
                && !campoApellidoMat.getText().equals("")) {
            b = true;
        }
        return b;
    }

    public boolean alMenosUnCampo() {
        if (telefono.getTelefono().getText().equals("") && celular.getCelular().getText().equals("")) {
            return false;
        }
        return true;
    }

    public int calcularEdad(String fecha) {
        String datetext = fecha;
        try {
            Calendar birth = new GregorianCalendar();
            Calendar today = new GregorianCalendar();
            int age = 0;
            int factor = 0;
            Date birthDate = new SimpleDateFormat("dd-MM-yyyy").parse(datetext);
            Date currentDate = new Date(); //current date
            birth.setTime(birthDate);
            today.setTime(currentDate);
            if (today.get(Calendar.MONTH) <= birth.get(Calendar.MONTH)) {
                if (today.get(Calendar.MONTH) == birth.get(Calendar.MONTH)) {
                    if (today.get(Calendar.DATE) > birth.get(Calendar.DATE)) {
                        factor = -1; //Aun no celebra su cumpleaÃ±os
                    }
                } else {
                    factor = -1; //Aun no celebra su cumpleaÃ±os
                }
            }
            age = (today.get(Calendar.YEAR) - birth.get(Calendar.YEAR)) + factor;
            if (age != -1) {
                return age;
            } else {
                return 0;
            }
        } catch (ParseException e) {
            return -1;
        }

    }

    public String capturarFecha() {
        Calendar cal = Calendar.getInstance();
        String fecha = "dd-MM-yyyy";
        if (this.dateChooserFechaNac.getDate() != null) {
            cal.setTime(this.dateChooserFechaNac.getDate());
            //Dia - mes - año
            fecha = Integer.toString(cal.get(Calendar.DAY_OF_MONTH)) + "-"
                    + Integer.toString(cal.get(Calendar.MONTH) + 1) + "-"
                    + Integer.toString(cal.get(Calendar.YEAR));
        }
        return fecha;
    }

    public void cargarDatosComboDerivacion() {
        java.util.List<service.ProfesionalExterno> lista = (java.util.List<service.ProfesionalExterno>) listarProfesionalesExternos();
        for (service.ProfesionalExterno prof : lista) {
            String nombre = prof.getNombres() + " " + prof.getApellidoPaterno() + " " + prof.getApellidoMaterno();
            this.comboDerivado.addItem(nombre);
        }
    }

    public void cargarDatosCombos() {
        java.util.List<service.Prevision> lista = (java.util.List<service.Prevision>) listarPrevisiones();
        Ordenar.ordena(lista, "nombre");
        for (service.Prevision prevision : lista) {
            this.comboBoxPrevision.addItem(prevision.getNombre());
        }
        java.util.List<service.EstadoCivil> listaEC = (java.util.List<service.EstadoCivil>) listarEstadosCiviles();
        for (service.EstadoCivil ec : listaEC) {
            this.comboBoxEstadoCivil.addItem(ec.getEstadoCivil());
        }

    }

    public boolean comboValido(JComboBox combo) {
        Boolean b = false;
        if (combo.getSelectedItem() != null) {
            if (combo.getSelectedItem().equals("") || combo.getSelectedItem().equals("Seleccionar")) {
                b = false;
            } else {
                b = true;
            }
        } else {
            b = false;
        }
        return b;
    }

    public JButton getBotonAceptar() {
        return this.botonAceptar;
    }

    public JButton getBotonCancelar() {
        return this.botonCancelar;
    }

    public void setRutEnabled(boolean b) {
        this.rut.getRut().setEnabled(b);
    }

    public void normalizarMensajeria() {
        mensajeriaInformacion.setText("Área de mensajería");
        mensajeriaInformacion.setForeground(Color.black);
    }

    public void limpiarCampos() {
        rut.getRut().setText("");
        campoNombres.setText("");
        campoApellidoPat.setText("");
        campoApellidoMat.setText("");
        comboBoxEstadoCivil.setSelectedItem((Object) "Seleccionar");
        comboBoxPrevision.setSelectedItem((Object) "Seleccionar");
        comboBoxSexo.setSelectedItem((Object) "Seleccionar");
        campoProfesion.setText("");
        campoEdad.setText("");
        dateChooserFechaNac.setDate(null);
        direccion.getRegion().setSelectedItem((Object) "Seleccionar");
        direccion.getProvincia().setSelectedItem((Object) "Seleccionar");
        direccion.getComuna().setSelectedItem((Object) "Seleccionar");
        direccion.getSector().setText("");
        direccion.getCalle().setText("");
        direccion.getNumero().setText("");
        direccion.getDepartamento().setText("");
        direccion.getBloque().setText("");
        telefono.getTelefono().setText("");
        celular.getCelular().setText("");
        email.getCorreo().setText("");
        comboDerivado.setSelectedItem((Object) "Seleccionar");
        normalizarMensajeria();
    }

    public void llenarCampos(service.Paciente p) {
        this.limpiarCampos();
        rut.getRut().setText(p.getRut());
        campoNombres.setText(p.getNombres());
        campoApellidoPat.setText(p.getApellidoPaterno());
        campoApellidoMat.setText(p.getApellidoMaterno());
        comboBoxEstadoCivil.setSelectedItem((Object) p.getEstadoCivil());
        comboBoxPrevision.setSelectedItem((Object) p.getPrevision());
        comboBoxSexo.setSelectedItem((Object) p.getSexo());
        campoProfesion.setText(p.getProfesion());
        if (!p.getFechaNac().equals("dd-MM-yyyy")) {
            this.dateChooserFechaNac.setDate(stringToDate(p.getFechaNac()));
        }
        direccion.getRegion().setSelectedItem((Object) p.getRegion());
        direccion.getProvincia().setSelectedItem((Object) p.getProvincia());
        direccion.getComuna().setSelectedItem((Object) p.getComuna());
        direccion.getSector().setText(p.getSector());
        direccion.getCalle().setText(p.getCalle());
        direccion.getNumero().setText(p.getNumero());
        direccion.getDepartamento().setText(p.getDepartamento());
        direccion.getBloque().setText(p.getBloque());
        telefono.getTelefono().setText(p.getTelefono());
        celular.getCelular().setText(p.getCelular());
        email.getCorreo().setText(p.getEmail());
        comboDerivado.setSelectedItem((Object) p.getDerivado());
    }

    public String llenarString(service.Paciente p) {
        String nombre = p.getNombres() + " " + p.getApellidoPaterno() + " " + p.getApellidoMaterno();
        String s = "Rut: " + p.getRut() + "\n"
                + "Nombre: " + nombre + "\n"
                + "Fecha de Nacimiento: " + p.getFechaNac() + "\n"
                + "Estado civil: " + p.getEstadoCivil() + "\n"
                + "Previsión: " + p.getPrevision() + "\n"
                + "Sexo: " + p.getSexo() + "\n"
                + "Profesión: " + p.getProfesion() + "\n"
                + "Región: " + p.getRegion() + "\n"
                + "Provincia: " + p.getProvincia() + "\n"
                + "Comuna: " + p.getComuna() + "\n"
                + "Sector: " + p.getSector() + "\n"
                + "Calle: " + p.getCalle() + "\n"
                + "Número: " + p.getNumero() + "\n"
                + "Departamento: " + p.getDepartamento() + "\n"
                + "Bloque: " + p.getBloque() + "\n"
                + "Teléfono: " + p.getTelefono() + "\n"
                + "Celular: " + p.getCelular() + "\n"
                + "E-mail: " + p.getEmail() + "\n"
                + "Derivado: " + p.getDerivado();
        return s;
    }

    public void modificarPac(service.Paciente sp, String comuna, String estadoCivil, String prevision, String provincia, String region, String sexo, String fecha, String derivado) {
        sp.setApellidoMaterno(campoApellidoMat.getText());
        sp.setApellidoPaterno(campoApellidoPat.getText());
        sp.setBloque(direccion.getBloque().getText());
        sp.setCalle(direccion.getCalle().getText());
        sp.setCelular(celular.getCelular().getText());
        sp.setComuna(comuna);
        sp.setDepartamento(direccion.getDepartamento().getText());
        sp.setEmail(email.getCorreo().getText());
        sp.setEstadoCivil(estadoCivil);
        sp.setFechaNac(fecha);
        sp.setNombres(campoNombres.getText());
        sp.setNumero(direccion.getNumero().getText());
        sp.setPrevision(prevision);
        sp.setProfesion(campoProfesion.getText());
        sp.setProvincia(provincia);
        sp.setRegion(region);
        sp.setSector(direccion.getSector().getText());
        sp.setTelefono(telefono.getTelefono().getText());
        sp.setSexo(sexo);
        sp.setDerivado(derivado);
        modificarPaciente(sp);
    }

    public Date stringToDate(String strFecha) {
        SimpleDateFormat formatoDelTexto = new SimpleDateFormat("dd-MM-yyyy");
        Date fecha = null;
        if (!strFecha.isEmpty()) {
            try {
                fecha = formatoDelTexto.parse(strFecha);
            } catch (ParseException ex) {
                ex.printStackTrace();
            }
            return fecha;
        }
        return null;

    }

    public String validarCombo(JComboBox combo) {
        if (comboValido(combo)) {
            return combo.getSelectedItem().toString();
        }
        return "";
    }

    public String validarFecha() {
        String fecha = capturarFecha();
        if (fecha.equals("dd-MM-yyyy")) {
            return "";
        }
        return fecha;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonCancelar;
    public javax.swing.JTextField campoApellidoMat;
    public javax.swing.JTextField campoApellidoPat;
    private javax.swing.JTextField campoEdad;
    public javax.swing.JTextField campoNombres;
    private javax.swing.JTextField campoProfesion;
    private componentes.Celular celular;
    private javax.swing.JComboBox comboBoxEstadoCivil;
    private javax.swing.JComboBox comboBoxPrevision;
    private javax.swing.JComboBox comboBoxSexo;
    private javax.swing.JComboBox comboDerivado;
    private com.toedter.calendar.JDateChooser dateChooserFechaNac;
    private componentes.Direccion direccion;
    private componentes.Correo email;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JLabel mensajeriaInformacion;
    public componentes.Rut rut;
    private componentes.Telefono telefono;
    // End of variables declaration//GEN-END:variables

    private static Object cargarPaciente(java.lang.String rut) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();
        return port.cargarPaciente(rut);
    }

    private static boolean modificarPaciente(service.Paciente arg0) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();
        return port.modificarPaciente(arg0);
    }

    private static Object cargarPrivilegios(java.lang.String rut) {
        service.PrivilegiosWS_Service service = new service.PrivilegiosWS_Service();
        service.PrivilegiosWS port = service.getPrivilegiosWSPort();
        return port.cargarPrivilegios(rut);
    }

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }

    private static boolean agregarPaciente(java.lang.String apellidoPaterno, java.lang.String apellidoMaterno, java.lang.String bloque, java.lang.String calle, java.lang.String celular, java.lang.String comuna, java.lang.String departamento, java.lang.String email, java.lang.String estadoCivil, java.lang.String fechaNac, java.lang.String nombres, java.lang.String numero, java.lang.String prevision, java.lang.String profesion, java.lang.String provincia, java.lang.String region, java.lang.String rut, java.lang.String sector, java.lang.String telefono, java.lang.String sexo, java.lang.String derivado, boolean visible) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();
        return port.agregarPaciente(apellidoPaterno, apellidoMaterno, bloque, calle, celular, comuna, departamento, email, estadoCivil, fechaNac, nombres, numero, prevision, profesion, provincia, region, rut, sector, telefono, sexo, derivado, visible);
    }

    private static java.util.List<service.ProfesionalExterno> listarProfesionalesExternos() {
        service.ProfesionalExternoWSService service = new service.ProfesionalExternoWSService();
        service.ProfesionalExternoWS port = service.getProfesionalExternoWSPort();
        return port.listarProfesionalesExternos();
    }

    private static java.util.List<service.Prevision> listarPrevisiones() {
        service.UtilidadesWS_Service service = new service.UtilidadesWS_Service();
        service.UtilidadesWS port = service.getUtilidadesWSPort();
        return port.listarPrevisiones();
    }

    private static java.util.List<service.EstadoCivil> listarEstadosCiviles() {
        service.UtilidadesWS_Service service = new service.UtilidadesWS_Service();
        service.UtilidadesWS port = service.getUtilidadesWSPort();
        return port.listarEstadosCiviles();
    }

    private static boolean isPacienteEnlazadoAProfesionalExterno(java.lang.String rutPaciente, java.lang.String rutProfesional) {
        service.EnlaceProfesionalExternoPacienteWSService service = new service.EnlaceProfesionalExternoPacienteWSService();
        service.EnlaceProfesionalExternoPacienteWS port = service.getEnlaceProfesionalExternoPacienteWSPort();
        return port.isPacienteEnlazadoAProfesionalExterno(rutPaciente, rutProfesional);
    }

    private static boolean agregarEnlaceProfesionalExternoPaciente(java.lang.String rutProfesional, java.lang.String rutPaciente) {
        service.EnlaceProfesionalExternoPacienteWSService service = new service.EnlaceProfesionalExternoPacienteWSService();
        service.EnlaceProfesionalExternoPacienteWS port = service.getEnlaceProfesionalExternoPacienteWSPort();
        return port.agregarEnlaceProfesionalExternoPaciente(rutProfesional, rutPaciente);
    }
}
